<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="钥匙号" prop="ysNum" class="item">
        <el-input
          v-model="queryParams.ysNum"
          placeholder="请输入钥匙号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="车辆型号" prop="carModel" class="item">
        <el-input
          v-model="queryParams.carModel"
          placeholder="请输入车辆型号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="VIN号" prop="vinNum" class="item">
        <el-input
          v-model="queryParams.vinNum"
          placeholder="请输入VIN号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="车辆类型" prop="carType" class="item">
        <el-select v-model="queryParams.carType" placeholder="请选择车辆类型" clearable size="small">
          <el-option
            v-for="dict in carTypeOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="规格型号" prop="model" class="item">
        <el-input
          v-model="queryParams.model"
          placeholder="请输入规格型号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="存放地点" prop="storeAddress" class="item">
        <el-input
          v-model="queryParams.storeAddress"
          placeholder="请输入存放地点"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="生产批次" prop="productionBatch" class="item">
        <el-input
          v-model="queryParams.productionBatch"
          placeholder="请输入生产批次"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="生产年月" class="item">
        <el-date-picker
          v-model="dateRange"
          size="small"
          style="width: 240px"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></el-date-picker>
      </el-form-item>
      <el-form-item label="项目名称" prop="projectNum" class="item">
        <el-input
          v-model="queryParams.projectNum"
          placeholder="请输入项目名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="样车状态" prop="carState" class="item">
        <el-select v-model="queryParams.carState" placeholder="请选择样车状态" clearable size="small">
          <el-option
            v-for="dict in carStateOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="使用状态" prop="carUseState" class="item">
        <el-select v-model="queryParams.carUseState" placeholder="请选择样车使用状态" clearable size="small">
          <el-option
            v-for="dict in carUseStateOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="cyan" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['trialproduce:car:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['trialproduce:car:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['trialproduce:car:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="info" icon="el-icon-upload2" size="mini" @click="handleImport" v-hasPermi="['trialproduce:car:import']">导入</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['trialproduce:car:export']"
        >导出</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleCarState"
          v-hasPermi="['trialproduce:car:carstate']"
        >样车状态</el-button>
      </el-col>
	  <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="carList" @selection-change="handleSelectionChange" border style="width: 100%"
    height="600">
      <el-table-column type="selection" width="55" align="center"/>
      <el-table-column label="主键ID" align="center" prop="carId" v-if="false" />
      <el-table-column label="钥匙号" align="center" prop="ysNum" fixed/>
      <el-table-column label="样车状态" align="center" prop="carState" :formatter="carStateFormat" />
      <el-table-column label="使用状态" align="center" prop="carUseState" :formatter="carUseStateFormat" />
      <el-table-column label="VIN号" align="center" prop="vinNum" />
      <el-table-column label="车辆型号" align="center" prop="carModel" />
      <el-table-column label="车辆类型" align="center" prop="carType" :formatter="carTypeFormat" />
      <el-table-column label="规格型号" align="center" prop="model" />
      <el-table-column label="计量单位" align="center" prop="unitName" />
      <el-table-column label="单价" align="center" prop="price" />
      <el-table-column label="现存状态描述" align="center" prop="stateContent" width="300"/>
      <el-table-column label="存放地点" align="center" prop="storeAddress" />
      <el-table-column label="生产批次" align="center" prop="productionBatch" />
      <el-table-column label="生产年月" align="center" prop="productionTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.productionTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="项目名称" align="center" prop="projectNum" />
      <el-table-column label="负责人" align="center" prop="userName" />
      <el-table-column prop="uri" label="样车图片" align="center" width="180">
        <template slot-scope="scope"> 
            <el-image
              style="width: 100px; height: 100px"
              :src="getFileUrl(scope.row.file)"
              :preview-src-list="getFileUrlList(scope.row.file)">
            </el-image>
        </template>
      </el-table-column>
      <el-table-column label="备注" align="center" prop="remark" />
      <el-table-column label="履历" align="center" prop="record" :show-overflow-tooltip="true"/>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width"   width="120"  fixed="right">
        
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleRepairDetail(scope.row)"
            v-hasPermi="['trialproduce:car:repairlist']"
          >维修记录</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-upload2"
            @click="handleImgUpload(scope.row)"
            v-hasPermi="['trialproduce:car:img']"
          >上传图片</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['trialproduce:car:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['trialproduce:car:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改样车对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="800px" append-to-body :close-on-click-modal="false">
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-row>
          <el-col :span="12">
            <el-form-item label="钥匙号" prop="ysNum">
              <el-input v-model="form.ysNum" placeholder="请输入钥匙号" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="VIN号" prop="vinNum">
              <el-input v-model="form.vinNum" placeholder="请输入VIN号" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="车辆型号" prop="carModel">
              <el-input v-model="form.carModel" placeholder="请输入车辆型号" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="车辆类型" prop="carType" >
              <el-select v-model="form.carType" placeholder="请选择车辆类型" style="width:100%">
                <el-option
                  v-for="dict in carTypeOptions"
                  :key="dict.dictValue"
                  :label="dict.dictLabel"
                  :value="dict.dictValue"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="规格型号" prop="model">
              <el-input v-model="form.model" placeholder="请输入规格型号" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="计量单位" prop="unitName">
              <el-input v-model="form.unitName" placeholder="请输入计量单位" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="单价" prop="price">
              <el-input v-model="form.price" placeholder="请输入单价" />
            </el-form-item>
          </el-col>
          
          <el-col :span="12">
            <el-form-item label="存放地点" prop="storeAddress">
              <el-input v-model="form.storeAddress" placeholder="请输入存放地点" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="生产批次" prop="productionBatch">
              <el-input v-model="form.productionBatch" placeholder="请输入生产批次" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="生产年月" prop="productionTime">
              <el-date-picker clearable size="small" style="width:100%"
                v-model="form.productionTime"
                type="date"
                value-format="yyyy-MM-dd"
                placeholder="选择生产年月">
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="项目名称" prop="projectNum">
              <el-input v-model="form.projectNum" placeholder="请输入项目名称" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="负责人" prop="userId">
              <treeselect v-model="form.userId" :options="userTree" :disable-branch-nodes="true" :show-count="false" placeholder="请选择用户" />
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="样车状态">
              <el-radio-group v-model="form.carState">
                <el-radio
                  v-for="dict in carStateOptions"
                  :key="dict.dictValue"
                  :label="parseInt(dict.dictValue)"
                >{{dict.dictLabel}}</el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="使用状态">
              <el-radio-group v-model="form.carUseState">
                <el-radio
                  v-for="dict in carUseStateOptions"
                  :key="dict.dictValue"
                  :label="parseInt(dict.dictValue)"
                >{{dict.dictLabel}}</el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="状态描述">
              <el-input v-model="form.stateContent"  type="textarea" :min-height="300"/>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="使用履历" prop="record">
              <el-input v-model="form.record" type="textarea" placeholder="请输入内容" />
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="备注" prop="remark">
              <el-input v-model="form.remark"  type="textarea" :min-height="300"/>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 导入对话框 -->
    <el-dialog :title="upload.title" :visible.sync="upload.open" width="400px" append-to-body :close-on-click-modal="false">
      <el-upload ref="upload" :limit="1" accept=".xlsx, .xls" :headers="upload.headers" :action="upload.url + '?updateSupport=' + upload.updateSupport" :disabled="upload.isUploading" :on-progress="handleFileUploadProgress" :on-success="handleFileSuccess" :auto-upload="false" drag>
        <i class="el-icon-upload"></i>
        <div class="el-upload__text">
          将文件拖到此处，或
          <em>点击上传</em>
        </div>
        <div class="el-upload__tip" slot="tip">
          <el-checkbox v-model="upload.updateSupport" />是否更新已经存在的数据
          <el-link type="info" style="font-size:12px" @click="importTemplate">下载模板</el-link>
        </div>
        <div class="el-upload__tip" style="color:red" slot="tip">提示：仅允许导入“xls”或“xlsx”格式文件！</div>
      </el-upload>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitFileForm">确 定</el-button>
        <el-button @click="upload.open = false">取 消</el-button>
      </div>
    </el-dialog>

     <!-- 上传图片对话框 -->
    <el-dialog :title="uploadImg.title" :visible.sync="uploadImg.open" width="800px" append-to-body :close-on-click-modal="false">
      <el-tabs v-model="uploadImg.activeName">
        <el-tab-pane id="processUserUpload" label="上传" name="first">
          <div class="el-upload__text">
              <el-select v-model="uploadImg.data.imagName" placeholder="请选择图片名称" style="width:100%">
                <el-option
                  v-for="dict in imagNameOptions"
                  :key="dict.dictValue"
                  :label="dict.dictLabel"
                  :value="dict.dictValue"
                ></el-option>
              </el-select>
          </div>
          <el-upload ref="uploadImg" :data="uploadImg.data"  :limit="1" accept=".jpg, .png,.jpeg" :headers="uploadImg.headers" 
          :action="uploadImg.url" :disabled="uploadImg.isUploading" :on-progress="handleImgUploadProgress" 
          :on-success="handleImgSuccess" :auto-upload="false" drag>
            <i class="el-icon-upload"></i>
            <div class="el-upload__text">
              将文件拖到此处，或
              <em>点击上传</em>
            </div>
            <div class="el-upload__tip" style="color:red" slot="tip">提示：仅允许导入“jpg”或“png”或“jpeg”格式的图片！</div>
          </el-upload>
        </el-tab-pane>
        <el-tab-pane label="附件查看" name="second">
          <el-table v-loading="loading" :data="uploadImg.fileLists" border @selection-change="handleSelectionFileChange" style="width: 100%"
          height="500">
                <el-table-column type="selection" width="55" align="center" />
                <el-table-column label="文件ID" align="center" prop="id" v-if="false"/>
                <el-table-column label="文件名称" align="center" prop="name"/>
                <el-table-column prop="uri" label="样车图片" align="center" width="180">
                  <template slot-scope="scope"> 
                      <el-image
                        style="width: 100px; height: 100px"
                        :src="getImgUrl(scope.row.uri)"
                        :preview-src-list="getImgUrlList(scope.row.uri)">
                      </el-image>
                  </template>
                </el-table-column>
                <el-table-column label="文件类型" align="center" prop="type" :formatter="stateFileTypeFormat"   v-if="false"/>
                <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
                  <template slot-scope="scope">
                    <el-button
                      size="mini"
                      type="text"
                      icon="el-icon-edit"
                      @click="handleFileDownload(scope.row)"
                    >下载</el-button>
                    <el-button
                      size="mini"
                      type="text"
                      icon="el-icon-delete"
                      @click="handleFileDelete(scope.row)"
                      v-hasPermi="['work:file:remove']"
                    >删除</el-button>
                  </template>
                </el-table-column>
          </el-table>
        </el-tab-pane>
      </el-tabs>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitImgForm">确 定</el-button>
        <el-button @click="uploadImg.open = false">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 修改样车状态 -->
    <el-dialog :title="repair.title" :visible.sync="repair.open" width="550px" append-to-body :close-on-click-modal="false">
      <el-form ref="repair.form" :model="repair.form" :rules="repair.rules" label-width="80px">
        <el-row>
          <el-col :span="24">
            <el-form-item label="样车状态">
              <el-radio-group v-model="repair.form.equipmentState" @change="isChangeState">
                <el-radio
                  v-for="dict in carStateOptions"
                  :key="dict.dictValue"
                  :label="parseInt(dict.dictValue)"
                >{{dict.dictLabel}}</el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="关联ID" prop="relIds"  v-if="false">
              <el-input v-model="repair.form.relIds" placeholder="请输入关联ID" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="表名" prop="tableName" v-if="false">
              <el-input v-model="repair.form.tableName" placeholder="请输入表名" />
            </el-form-item>
          </el-col>
          <el-col :span="24" v-if="repair.isShow">
            <el-form-item label="维修时限" prop="repairDaterange">
              <el-date-picker
                  v-model="repair.form.repairDaterange"
                  size="medium"
                  name="se"
                  style="width: 350px"
                  value-format="yyyy-MM-dd"
                  type="daterange"
                  range-separator="-"
                  start-placeholder="开始日期"
                  end-placeholder="结束日期"
                ></el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="20" v-if="repair.isShow">
            <el-form-item label="维修内容" prop="content">
              <el-input v-model="repair.form.content"  show-word-limit  type="textarea" placeholder="请输入维修内容" maxlength="800" />
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="使用状态">
              <el-radio-group v-model="repair.form.equipmentUseState">
                <el-radio
                  v-for="dict in carUseStateOptions"
                  :key="dict.dictValue"
                  :label="parseInt(dict.dictValue)"
                >{{dict.dictLabel}}</el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitRepairForm">确 定</el-button>
        <el-button @click="cancelRepair">取 消</el-button>
      </div>
    </el-dialog>
    <!-- 查看维修信息对话框 -->
    <el-dialog :title="repairDetail.title" :visible.sync="repairDetail.open" width="800px" append-to-body >
        <el-table v-loading="loading" :data="repairDetail.repairList" @selection-change="handleSelectionChange">
          <el-table-column label="开始时间" align="center" prop="startTime" width="180">
            <template slot-scope="scope">
              <span>{{ parseTime(scope.row.startTime, '{y}-{m}-{d}') }}</span>
            </template>
          </el-table-column>
          <el-table-column label="结束时间" align="center" prop="finishTime" width="180">
            <template slot-scope="scope">
              <span>{{ parseTime(scope.row.finishTime, '{y}-{m}-{d}') }}</span>
            </template>
          </el-table-column>
          <el-table-column label="维修内容" align="center" prop="content" />
      </el-table>
    </el-dialog>
  </div>
</template>

<script>
import { listCar, getCar, delCar, addCar, updateCar, exportCar, importTemplate, selectFiles, deleteFiles, getUserTree, changeState, listRepair } from "@/api/trialproduce/car";
import Editor from '@/components/Editor';
import { getToken } from "@/utils/auth";
import Treeselect from "@riophae/vue-treeselect";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";
export default {
  name: "Car",
  components: { Editor,Treeselect },
  data() {
    return {
      //基础路径
      baseURL : process.env.VUE_APP_BASE_API,
      // 日期范围
      dateRange: [],
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 样车表格数据
      carList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 车辆类型字典
      carTypeOptions: [],
      // 样车状态字典
      carStateOptions: [],
      // 样车使用状态字典
      carUseStateOptions: [],
      //文件类型
      textFileTypeOptions: [],
      //图片名称字典
      imagNameOptions: [],
      //用户数结构
      userTree:[],
      //用户数过滤
      filterText: '',
      //默认树列表字段
      defaultProps: {
        children: 'children',
        label: 'label'
      },
       //导入参数
      upload: {
        // 是否显示弹出层（导入）
        open: false,
        // 弹出层标题（导入）
        title: "",
        // 是否禁用上传
        isUploading: false,
        // 是否更新已经存在的数据
        updateSupport: 0,
        // 设置上传的请求头部
        headers: { Authorization: "Bearer " + getToken() },
        // 上传的地址
        url: process.env.VUE_APP_BASE_API + "/trialproduce/car/importData",
      },
      //导入图片
      uploadImg: {
        // 上传标签页
        activeName: 'first',
        
        //文件列表
        fileLists: [{
            id:'',
            url: "",
            name: '',
            type: ''
        }],
        //总数
        total: 0,
        // 是否显示弹出层（导入）
        open: false,
        // 弹出层标题（导入）
        title: "",
        // 是否禁用上传
        isUploading: false,
        // 是否更新已经存在的数据
        updateSupport: 0,
        //上传数据
        data:{
          tableId: null,
          //图片名称
          imagName: ''
        },
        // 设置上传的请求头部
        headers: { Authorization: "Bearer " + getToken() },
        // 上传的地址
        url: process.env.VUE_APP_BASE_API + "/trialproduce/car/upload",
      },
      //修改状态信息
      repair: {
        // 是否显示弹出层（导入）
        open: false,
        // 弹出层标题（导入）
        title: "",
        //显示隐藏维修内容
        isShow: false,
        //表单
        form: {

        },
        // 表单校验
        rules: {
            content: [
              { required: true, message: "维修内容不能为空", trigger: "blur" }
            ],
            repairDaterange: [
              {
                type: 'array',
                required: true,
                message: '请选择日期区间',
                fields: {
                  //tpye类型试情况而定,所以如果返回的是date就改成date
                  0: { type: 'string', required: true, message: '请选择开始日期' },
                  1: { type: 'string', required: true, message: '请选择结束日期' }
                }
              }
            ]
        }
      },
      //维修详情
      repairDetail: {
        // 是否显示弹出层（导入）
        open: false,
        // 弹出层标题（导入）
        title: "",
        //维修表单
        repairList: [],
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          relId: null,
          tableName: null,
          startTime: null,
          finishTime: null,
          relFinishTime: null,
          content: null
        },
      },
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        ysNum: null,
        carModel: null,
        vinNum: null,
        carType: null,
        model: null,
        storeAddress: null,
        productionBatch: null,
        productionTime: null,
        projectNum: null,
        carState: null,
        carUseState: null,
        //工时范围
        dateRange:[],
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
    this.handleUserTree();
    this.getDicts("sample_car_type").then(response => {
      this.carTypeOptions = response.data;
    });
    this.getDicts("sample_car_state").then(response => {
      this.carStateOptions = response.data;
    });
    this.getDicts("sample_car_use_state").then(response => {
      this.carUseStateOptions = response.data;
    });
    this.getDicts("sys_file_type").then(response => {
      this.textFileTypeOptions = response.data;
    });
    this.getDicts("sample_car_image").then(response => {
      this.imagNameOptions = response.data;
    });
    
  },
  watch: {
    filterText(val) {
      this.$refs.tree.filter(val);
    }
  },
  methods: {
    /** 查询样车列表 */
    getList() {
      this.loading = true;
      listCar(this.addDateRange(this.queryParams, this.dateRange)).then(response => {
        this.carList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 车辆类型字典翻译
    carTypeFormat(row, column) {
      return this.selectDictLabel(this.carTypeOptions, row.carType);
    },
    // 样车状态字典翻译
    carStateFormat(row, column) {
      return this.selectDictLabel(this.carStateOptions, row.carState);
    },
    // 样车使用状态字典翻译
    carUseStateFormat(row, column) {
      return this.selectDictLabel(this.carUseStateOptions, row.carUseState);
    },
     // 文件类型翻译
    stateFileTypeFormat(row, column) {
      return this.selectDictLabel(this.textFileTypeOptions, row.type);
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        carId: null,
        ysNum: null,
        carModel: null,
        vinNum: null,
        carType: null,
        model: null,
        unitName: null,
        price: null,
        stateContent: null,
        storeAddress: null,
        productionBatch: null,
        productionTime: null,
        projectNum: null,
        userId: null,
        carState: 0,
        carUseState: 0,
        remark: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      //工时范围
      this.dateRange = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.carId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加样车";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const carId = row.carId || this.ids
      getCar(carId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改样车";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.carId != null) {
            updateCar(this.form).then(response => {
              if (response.code === 200) {
                this.msgSuccess("修改成功");
                this.open = false;
                this.getList();
              }
            });
          } else {
            addCar(this.form).then(response => {
              if (response.code === 200) {
                this.msgSuccess("新增成功");
                this.open = false;
                this.getList();
              }
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const carIds = row.carId || this.ids;
      this.$confirm('是否确认删除样车编号为"' + carIds + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delCar(carIds);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        }).catch(function() {});
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有样车数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return exportCar(queryParams);
        }).then(response => {
          this.download(response.msg);
        }).catch(function() {});
    },
    /** 导入按钮操作 */
    handleImport() {
      this.upload.title = "样车导入";
      this.upload.open = true;
    },
    /** 下载模板操作 */
    importTemplate() {
      importTemplate().then((response) => {
        this.download(response.msg);
      });
    },
     // 文件上传中处理
    handleFileUploadProgress(event, file, fileList) {
      this.upload.isUploading = true;
    },
    // 文件上传成功处理
    handleFileSuccess(response, file, fileList) {
      this.upload.open = false;
      this.upload.isUploading = false;
      this.$refs.upload.clearFiles();
      this.$alert(response.msg, "导入结果", { dangerouslyUseHTMLString: true });
      this.getList();
    },
    // 提交上传文件
    submitFileForm() {
      this.$refs.upload.submit();
    },
    /** 图片上传按钮操作 */
    handleImgUpload(row) {
      const carId = row.carId || this.ids
      this.uploadImg.title = "上传图片";
      this.uploadImg.open = true;
      this.uploadImg.data.tableId = carId;
      this.getFileList();
    },
    // 图片上传中处理
    handleImgUploadProgress(event, file, fileList) {
      this.uploadImg.isUploading = true;
    },
    // 图片上传成功处理
    handleImgSuccess(response, file, fileList) {
      this.uploadImg.open = true;
      this.uploadImg.isUploading = false;
      this.$refs.uploadImg.clearFiles();
      this.uploadImg.data.imagName = ''
      this.$alert(response.msg, "上传结果", { dangerouslyUseHTMLString: true });
      this.getFileList();
      this.getList();
    },
    // 图片提交上传文件
    submitImgForm() {
      if(this.uploadImg.data.imagName==''){
          this.$message("请选择图片名称");
          return;
      }
      this.$refs.uploadImg.submit();
    },
    //图片列表
    handleSelectionFileChange(selection){
      this.id = selection.map(item => item.id)
      this.uri = selection.map(item => item.uri)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 查询附件列表 */
    getFileList() {
      this.loading = true;
      selectFiles(this.uploadImg.data.tableId).then((response) => {
        this.uploadImg.fileLists = response.rows;
        this.uploadImg.total = response.total;
        this.loading = false;
      });
    },
    // 删除文件操作
    handleFileDelete(row){
      const id = row.id || this.id;
      this.$confirm('是否确认删除任务分配编号为"' + id + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return deleteFiles(id);
        }).then(() => {
          this.getFileList();
          this.msgSuccess("删除成功");
        }).catch(function() {});
    },
    // 下载文件
    handleFileDownload(row){
      const id = row.id || this.id;
      const url = row.uri || this.uri;
      window.location.href = this.baseURL+url;
    },
    //拼接图片路径
    getImgUrl(uri){
      if(null==uri||""==uri){
         return require("@/assets/image/profile.jpg");
      }else{
        return this.baseURL+"/"+uri;
      }
    },
    //大图预览
    getImgUrlList(uri){
      if(null==uri||""==uri){
         return [require("@/assets/image/profile.jpg")];
      }else{
        return  [this.baseURL+"/"+uri];
      }
    },
    //拼接图片路径返回第一张图片
    getFileUrl(file){
      var uri ="";
      if(null==file||""==file){
         return require("@/assets/image/profile.jpg");
      }else{
         for(var i=0;i<file.length;i++){
              if(file[i].name=="正视图"){
                  uri = this.baseURL+"/"+ file[i].uri;
              }
        }
        if(uri==""){
            uri = this.baseURL+"/"+ file[0].uri;
        }
        return uri;
      }
    },
    //大图预览
    getFileUrlList(file){
      var  list = [];
      if(null==file||""==file){
         return [require("@/assets/image/profile.jpg")];
      }else{
        for(var i=0;i<file.length;i++){
              list.push(this.baseURL+"/"+file[i].uri);
        }
        return  list;
      }
    },
    //修改样车状态
    handleCarState(){
      this.repair.open = true;
      this.repair.title = "样车状态变更";
    },
    //用户树
    filterNode(value, data) {
      if (!value) return true;
      return data.label.indexOf(value) !== -1;
    },
    //用户树
    handleUserTree(){
      getUserTree().then(response => {
        this.userTree = response.data;
      });
    },
    //状态变更，动态显示输入框
    isChangeState(value){
        if(value==1){
          this.repair.isShow = true;
        }else{
          this.repair.isShow = false;
        }
    },
    // 取消按钮
    cancelRepair() {
      this.repair.open = false;
      this.repairReset();
    },
    // 维修表单重置
    repairReset(){
      this.repair.form = {
        tableName : 1,
        equipmentState : null,
        relIds : null,
        repairDaterange : [],
        content : "",
        equipmentUseState : ""
      };
      this.repair.isShow = false;
      this.resetForm("repair.form");
    },
    submitRepairForm(row){
      const carId = row.carId || this.ids
      this.repair.form.relIds = carId;
      this.repair.form.tableName = 3;
      this.$refs["repair.form"].validate(valid => {
        if (valid) {
            changeState(this.addMyDateRange(this.repair.form, this.repair.form.repairDaterange)).then(response => {
              if (response.code === 200) {
                this.msgSuccess("状态更改成功");
                this.repair.open = false;
                this.repairReset();
                this.getList();
              }
            });
        }
      });
    },
     //维修工单详情
    handleRepairDetail(row){
      this.repairDetail.queryParams.relId = row.carId;
      this.repairDetail.queryParams.tableName = "3";
      listRepair(this.repairDetail.queryParams).then(response => {
        this.repairDetail.repairList = response.rows;
      });
      this.repairDetail.open = true;
      this.title = "维修详情";
    }
  },
  
};
</script>
<style>
.el-upload-list__item-name{
    font-size: 16px;
}
#processUserUpload .el-upload-dragger{
  display:block;
  margin:0 auto;
  margin-top:1em;
  width: 760px;
  height: 180px;
}
</style>